import axios from "axios";
import nProgress from "/node_modules/nprogress/nprogress";
import "nprogress/nprogress.css";
import { getToken } from "../auth/auth";

const request = axios.create({
  baseURL: "/api",
});

request.interceptors.request.use(
  (config) => {
    nProgress.start();
    const token = localStorage.getItem("token");
    // const token =
    //   "eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjEsInBhc3N3b3JkIjoiMTIzNDU2IiwicGhvbmUiOiIxMjM0NTYiLCJyb2xlX2lkIjozLCJleHAiOjE3MTU5NjQyNzN9.NK0J9C7HbooHHPdI5XtoHickGFJhZiPgL4V83fl8asE";
    config.headers["Content-Type"] = "application/json;charset=utf-8";

    config.headers["token"] = token;

    return config;
  },
  (e) => Promise.reject(e)
);

request.interceptors.response.use(
  (res) => {
    nProgress.done();
    // console.log("Response Headers:", res.headers);
    return res;
  },
  (e) => Promise.reject(e)
);

export default request;
